from django.db import models
import django.utils.timezone as timezone
#用户表
class User(models.Model):
    #账户
    username = models.CharField(max_length=32,primary_key=True, verbose_name='账户')
    #密码
    password = models.CharField(max_length=16, verbose_name='密码')
    #昵称
    nickname = models.CharField(max_length=16, verbose_name='昵称')
    #电子邮箱
    email = models.EmailField(verbose_name='电子邮件')
    #年龄
    #age = models.IntegerField(default=0)
    #认证情况
    certification = models.IntegerField(default=0, verbose_name='认证情况')
    #真实姓名
    identity = models.CharField(max_length=32,default='未认证', verbose_name='真实姓名')
    #公益积分
    integral = models.IntegerField(default=0, verbose_name='公益积分')
    #个人介绍
    introduction = models.TextField(default='这个人很勤快，还没有写评论！', verbose_name='个人介绍')
    #头像
    avatar = models.TextField(default='https://img.antmoe.com/avatar.jpg', verbose_name='头像')

    def __str__(self):
        return   self.username

    class Meta:
        verbose_name_plural = '用户表'

#用户动态表
class Dynamic(models.Model):
    #发起人
    launch_user = models.ForeignKey(to='User',to_field='username', verbose_name='发起人')
    #时间
    add_date = models.DateTimeField('保存日期',default = timezone.now)
    mod_date = models.DateTimeField('最后修改日期', auto_now = True)
    #点赞
    like = models.IntegerField(default=0, verbose_name='点赞')
    #动态内容
    context = models.TextField(default="", verbose_name='动态内容')
    class Meta:
        ordering = ['-add_date']
        verbose_name_plural = '用户动态表'



#用户动态图片
class Dynamic_img(models.Model):
    # 图片
    img = models.TextField( verbose_name='图片')
    # 图片
    dynamic_img = models.ForeignKey(to="Dynamic", to_field="id", verbose_name='图片')
    class Meta:
        verbose_name_plural = '用户动态图片'


#动态评论表
class Comments_dynamic(models.Model):
    #对应动态ID
    sponsor = models.ForeignKey(to=Dynamic, verbose_name='对应动态的ID')
    #评论人
    commentator = models.ForeignKey(to='User',to_field='username', verbose_name='评论人')
    #内容
    content = models.TextField()
    #time
    add_date = models.DateTimeField('保存日期', default=timezone.now)
    mod_date = models.DateTimeField('最后修改日期', auto_now=True)

    class Meta:
        verbose_name_plural = '动态评论表'
#关注表
class Attention(models.Model):
    #当前用户
    username = models.ForeignKey(to='User',to_field='username',related_name='now_user', verbose_name='当前用户',blank=False)
    #关注的用户
    attention_user = models.ForeignKey(to='User',to_field='username',related_name='follow_user', verbose_name='关注的人')

    class Meta:
        verbose_name_plural = '关注表'
#项目表
class Projects(models.Model):
    #创建的社团
    community = models.ForeignKey(to='Community', to_field='id', verbose_name='创建的社团')
    #项目名
    title = models.CharField(default="无名称",max_length=32, verbose_name='项目名')
    #召集人数
    num = models.IntegerField(default=10, verbose_name='召集人数')
    #项目详情
    details = models.TextField(verbose_name='项目详情')
    #项目目的
    purpose = models.TextField(verbose_name='项目目的')
    #项目进展
    progress = models.IntegerField( verbose_name='项目进展')
    #是否结束
    finish = models.IntegerField(default=0, verbose_name='是否结束')
    #时间
    add_date = models.DateTimeField('保存日期', default=timezone.now)
    def __str__(self):
        return self.title
    class Meta:
        verbose_name_plural = '项目表'

#项目留言表
class Comments_projects(models.Model):
    #对应的项目
    project_id = models.ForeignKey(to="Projects",to_field='id', verbose_name='对应项目的id')
    #留言人
    commentator = models.ForeignKey(to='User', to_field='username', verbose_name='留言人')
    # 内容
    content = models.TextField( verbose_name='内容')
    # time
    add_date = models.DateTimeField('保存日期', default=timezone.now)
    mod_date = models.DateTimeField('最后修改日期', auto_now=True)
    
    class Meta:
        verbose_name_plural = '项目留言表'
#收藏表
class Favorite(models.Model):
    #当前用户
    username = models.ForeignKey(to='User', to_field='username', verbose_name='当前用户')
    #收藏的项目id
    pid = models.ForeignKey(to='Projects',to_field='id', verbose_name='收藏项目的id')

    class Meta:
        verbose_name_plural = '收藏表'
#社团表
class Community(models.Model):
    #开创用户
    username = models.ForeignKey(to='User',to_field='username',related_name='first_user', verbose_name='开创用户(创建人)')
    #社长
    president = models.ForeignKey(to='User',to_field='username',related_name='president', verbose_name='社长')
    #创建时间
    add_date = models.DateTimeField('保存日期', default=timezone.now)
    #社团名
    name = models.CharField(max_length=16, verbose_name='社团名')
    #社团人数(可能不用)
    num = models.IntegerField(default=0, verbose_name='社团人数')
    #社团头像
    avatar = models.TextField(default='https://img.antmoe.com/avatar.jpg', verbose_name='社团头像')
    #创建的项目数
    project_num = models.IntegerField(default=0, verbose_name='创建的项目数')
    def __str__(self):
        return self.name
    class Meta:
        verbose_name_plural = '社团表'

#加入的社团
class Join_community(models.Model):
    #社团id
    community_id = models.ForeignKey(to='Community',to_field='id', verbose_name='社团id')
    #加入用户
    username = models.ForeignKey(to='User',to_field="username", verbose_name='加入的用户')
    #时间
    add_date = models.DateTimeField('保存日期', default=timezone.now)
    def __str__(self):
        return '%s-<%s'%(self.community_id , self.username)
    class Meta:
        verbose_name_plural = '加入的社团'

#加入项目表
class Join_project(models.Model):
    #用户名
    username = models.ForeignKey(to='User',to_field='username', verbose_name='用户名')
    #项目id
    project_id = models.ForeignKey(to='Projects', verbose_name='项目id')
    def __str__(self):
        return '%s-<%s'%(self.username , self.project_id)
    class Meta:
        verbose_name_plural = '加入的项目'

#社团动态
class Community_dynamic(models.Model):
    # 发起的社团
    launch_user = models.ForeignKey(to='Community', verbose_name='发起的社团')
    # 时间
    add_date = models.DateTimeField('保存日期', default=timezone.now)
    mod_date = models.DateTimeField('最后修改日期', auto_now=True)
    # 动态内容
    context = models.TextField( verbose_name='内容')

    def __str__(self):
        return '%s'%(self.launch_user)
    class Meta:
        verbose_name_plural = '社团动态'
#社团动态图片
class Community_dynamic_img(models.Model):
    # 图片
    img = models.TextField()
    # 图片
    community_img = models.ForeignKey(to="Community_dynamic", to_field="id", verbose_name='图片')
    class Meta:
        verbose_name_plural = '社团动态图片'
    def __str__(self):
        return '%s'%(self.community_img)
#积分商城
class Shop(models.Model):
    #谁的商品
    username = models.ForeignKey(to="User",to_field="username", verbose_name='谁的商品')
    #商品价值
    value = models.IntegerField(default=0, verbose_name='商品的价值')
    #商品头图
    img = models.TextField(default="https://img.antmoe.com/avator.jpg", verbose_name='商品的头图')
    #商品描述
    desc = models.TextField(default='送人玫瑰，手有余香！', verbose_name='商品的描述')
    # 时间
    add_date = models.DateTimeField('保存日期', default=timezone.now)
    mod_date = models.DateTimeField('最后修改日期', auto_now=True)
    class Meta:
        verbose_name_plural = '积分商城'
    def __str__(self):
        return '%s'%(self.username)

#全局公告类
class Announcement(models.Model):
    #首页公告
    announcement = models.CharField(max_length=120, verbose_name='首页公共')
    class Meta:
        verbose_name_plural = '公告'
    def __str__(self):
        return '%s'%(self.announcement)
#项目图片
class Projects_img(models.Model):
    details_img=models.CharField(max_length=120)
    purpose_img=models.CharField(max_length=120)
    background=models.CharField(max_length=120)
    project_id = models.ForeignKey(to='Projects', to_field="id")
    class Meta:
        verbose_name_plural = '项目图片'
    def __str__(self):
        return '%s'%(self.project_id)
#公益文章
class Commonweal_article(models.Model):
    #创建人
    create_people= models.ForeignKey(to='User', to_field="username", verbose_name='创建人')
    #标题
    title=models.CharField(max_length=120, verbose_name='标题')
    #内容
    content=models.TextField( verbose_name='内容')
    # 时间
    add_date = models.DateTimeField('保存日期', default=timezone.now)
    class Meta:
        verbose_name_plural = '公益文章'
    def __str__(self):
        return '%s'%(self.title)
#公益文章的图片
class Article_img(models.Model):
    #图片
    img=models.TextField()
    # 图片
    article_img = models.ForeignKey(to="Commonweal_article", to_field="id", verbose_name='图片')
    class Meta:
        verbose_name_plural = '公益文章的图片'
    def __str__(self):
        return '%s'%(self.article_img)